package com.uzhie.web.service.listener;

import com.uzhie.component.VideoAnalyseComponent;
import com.uzhie.jt808.jt1078.entity.JT_1005;
import org.springframework.beans.factory.annotation.Autowired;

import javax.jms.BytesMessage;
import javax.jms.Message;

/**
 * Created by TangFei on 2018/10/11.
 */
public class MQPassengerReceiveService implements MQReceiveService {

    @Autowired
    private VideoAnalyseComponent videoAnalyseComponent;

    @Override
    public void onMessage(Message message) {
        LOGGER.fatal("收到乘客流量信息");
        handlerPassenger(message);
    }

    //处理客流量上传
    private void handlerPassenger(Message message) {
        try {
            String mSimNumber = message.getStringProperty(PARAM);
            LOGGER.info(" 客流量消息@车辆内置SIM卡@ 卡号为 : [" + mSimNumber + "] --->");
            //获取消息体内容
            BytesMessage bytesMessage = (BytesMessage) message;
            byte[] body = new byte[(int) bytesMessage.getBodyLength()];
            LOGGER.info(" 远程客流量消息长度 : [" + bytesMessage.getBodyLength() + "]--->");
            bytesMessage.readBytes(body);
            LOGGER.info("客流量消息body消息内容为 : [" + body.toString() + " ]--->");
            JT_1005 order = new JT_1005();
            order.ReadFromBytes(body);
            LOGGER.info(" 转换后的客流量内容为 : [ " + order.toString() + " ] --->");
            videoAnalyseComponent.addPassenger(order, mSimNumber);
        } catch (Exception e) {
            LOGGER.error("客流量上传异常", e);
        }
    }
    
}
